<template>
  <h1>猜数字练习</h1>
  <input type="text" v-model="num" placeholder="请输入你猜的数字">
  <button @click="guess">猜一猜</button>
  <h4>小提示:{{result}}</h4>
</template>

<script setup>
  import {ref} from "vue";

  const num = ref('');
  const result = ref('');
  //生成一个随机数
  let n = parseInt(Math.random()*100)+1;
  console.log('我是后台:'+n);
  //定义方法猜数字
  const guess = ()=>{
    if(num.value>n){
      result.value = '猜大了';
    }else if(num.value<n){
      result.value = '猜小了';
    }else{
      result.value = '猜对了!';
    }
  }

</script>

<style scoped>

</style>